package com.sapient.service.parser;

import com.sapient.service.QuestionDTO;

public enum ResponseParser {
	TOKENPARSER(){

		@Override
		public String parse(String responseString) {
			return responseString.substring(responseString.indexOf(':')+1, responseString.length()).trim();
		}
		
	},
	QUESTION_PARSER(){

		@Override
		public QuestionDTO parse(String responseString) {
			final String[] tokens = responseString.split(" ");
			return new QuestionDTO(
					Integer.parseInt(tokens[2]),
					Integer.parseInt(tokens[tokens.length-1].substring(0, tokens[tokens.length-1].indexOf('?'))),
					tokens[3]);
		}
		
	},
	RESULT_PARSER(){
		private static final String PASS = "pass";
		
		@Override
		public Boolean parse(String responseString) {
			return PASS.equals(responseString);
		}
		
	};
   //template method
   public abstract Object parse(String responseString);
}
